<template>
  <Dialogdrawerdefect
    :ddtvisible="visible"
    size="1000px"
    direction="rtl"
    :has-modal="true"
    :modal="true"
    :close-on-click-modal="true"
    @close="handleClose">
    <div class="cont_box" v-loading="loading">
      <AppInfoTitle>
        <b class="fs-16">日志详情</b>
      </AppInfoTitle>
      <el-table
        ref="table"
        v-loading="loading"
        size="medium"
        :data="tableData"
        style="width: 100%"
        border
        class="ky-table"
        highlight-current-row
      >
        <el-table-column type="expand">
          <template slot-scope="scope">
            <div class="code">
              <div class="c_col">
                <div class="c_lab">模块名称：</div>
                <div class="c_cnt">{{scope.row.moduleName}}</div>
              </div>
              <div class="c_col">
                <div class="c_lab">操作：</div>
                <div class="c_cnt">{{scope.row.fthings}}</div>
              </div>
              <div class="c_col">
                <div class="c_lab">操作时间：</div>
                <div class="c_cnt">{{scope.row.ftime}}</div>
              </div>
              <div class="c_col">
                <div class="c_lab">IP地址：</div>
                <div class="c_cnt">{{scope.row.mac}}</div>
              </div>
              <div class="c_col">
                <div class="c_lab">相关日志Id：</div>
                <div class="c_cnt">{{scope.row.flogId}}</div>
              </div>
              <div class="c_col">
                <div class="c_lab">内容：</div>
                <div class="c_cnt">
                  <div v-if="scope.row.allcontentTxt" v-html="scope.row.allcontentTxt"></div>
                  <div v-if="!scope.row.allcontentTxt" v-html="scope.row.allcontent"></div>
                </div>
              </div>
              <div class="c_col">
                <div class="c_lab">对比：</div>
                <div class="c_cnt">
                  <div v-html="scope.row.allcontentContrast"></div>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="fthings" label="操作" width="100">
          <template slot-scope="scope">
            <el-tag size="small" :type="scope.row.fthings === '取消预约'?'danger':'primary'">{{scope.row.fthings}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="patientName" label="患者姓名" show-overflow-tooltip></el-table-column>
        <el-table-column prop="dep" label="部门"></el-table-column>
        <el-table-column prop="checkpos" label="检查项目" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="patientXno" label="影像号xno" min-width="150"></el-table-column>
        <el-table-column prop="ftime" label="操作时间" width="180"></el-table-column>
        <el-table-column prop="foperatorno" label="操作人员" show-overflow-tooltip></el-table-column>
        <el-table-column prop="mac" label="IP地址" width="120"></el-table-column>
        <el-table-column prop="conclusion" label="报告诊断" show-overflow-tooltip></el-table-column>
        <el-table-column prop="describle" label="报告描述" show-overflow-tooltip></el-table-column>
      </el-table>
      <div class="log_total" v-if="tableData.length>0">共：{{tableData.length}} 条</div>
      <div class="buttons">
        <div class="right-buttons">
          <el-button size="small" @click="handleClose">关 闭</el-button>
        </div>
      </div>
    </div>
  </Dialogdrawerdefect>
</template>
<script>
import Dialogdrawerdefect from '@/components/dialogbox/dialogDrawer'
import compareInfo from '@/utils/compareInfo'
import AppInfoTitle from '@/components/appInfoTitle/index'
import { getFlogList } from '@/api/api.js'
export default {
  name: 'EditDialog',
  components: {
    Dialogdrawerdefect,
    AppInfoTitle
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    id: {
      String,
      default: ''
    },
    hospitalCode: {
      String,
      default: ''
    }
  },
  data() {
    return {
      tableData: [],
      allContentArr: {},
      appointmentDateTime: '',
      loading: false,
      showTextarea: false,
      applyInfoHospital: window.g.applyInfoHospital || ''
    }
  },
  computed: {
    visible: {
      get() {
        return this.dialogVisible
      },
      set(val) {
        this.$emit('update:dialogVisible', val)
      }
    }
  },
  watch: {
    // id(val) {
    //   if (val) {
    //     this.getDetail(val)
    //   }
    // }
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    async getDetail(id) {
      await this.$getHospitalList()
      this.loading = true
      getFlogList({ AccessNo: id, hospitalCode: this.hospitalCode }).then(res => {
        this.loading = false
        if (res && res.code === 10000) {
          const _list = res.content.list
          const len = _list.length
          let count = len - 1
          while (count >= 0) {
            const item = _list[count]
            if (this.applyInfoHospital === 'wzszxyy' || this.hospitalCode === '47052555733030211A1001') {
              const contentNoChange = JSON.parse(JSON.stringify(item.allcontent))
              // 使用正则表达式匹配预约时间后面的时间部分
              var match = contentNoChange.match(/预约时间：(.*?)；/) || item.allcontentTxt.match(/预约时间:(.*?);/)
              // 如果找到匹配项，则输出匹配的时间
              if (match && match.length > 1) {
                item.appointmentDateTime = match[1]
              } else {
                item.appointmentDateTime = ''
              }
            }
            const _idx = this.mx_hospitalList.findIndex(hosp => hosp.code === item.hospitalCode)
            if (_idx >= 0) {
              item.hospitalName = this.mx_hospitalList[_idx].name
            }

            // 痕迹对比
            item.allcontentContrast = ''
            item.allcontentTxt = ''
            if (count < len - 1) {
              let op = compareInfo.eq({
                preInfo: item.allcontent,
                preInfoLabel: _list[count + 1].allcontent
              })
              item.allcontentTxt = op.preInfo
              item.allcontentContrast = op.preInfoLabel
            } else {
              item.allcontentTxt = item.allcontent
            }
            count--
            this.tableData = _list
          }
          this.tableData = _list
        }
      }).catch(() => {
        this.loading = false
      })
    },
    dealAllContent() {
      this.allContentArr = {}
      let ac = this.ruleForm.allcontent
      if (ac) {
        // console.log('ac', ac)
        ac = ac.replaceAll('。', '')
        let index1 = 0// 病人基本信息
        let index2 = ac.indexOf('病人检查信息')
        let index3 = ac.indexOf('病人预约信息')
        let str1 = ac.substring(index1 + 6, index2)// 病人基本信息
        let str2 = ac.substring(index2 + 6, index3)// 病人检查信息
        let str3 = ac.substring(index3 + 6)// 病人预约信息
        let allStr = {
          '病人基本信息': str1,
          '病人检查信息': str2,
          '病人预约信息': str3
        }
        for (let key in allStr) {
          let strArr = allStr[key].split('；')
          let obj = {}
          for (let i = 0; i < strArr.length; i++) {
            let arr = strArr[i].split('：')
            if (arr[0] !== '操作人员') {
              obj[arr[0]] = arr[1]
            }
          }
          this.allContentArr[key] = obj
        }
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.code{
  padding:20px;
  background-color: #263444;
  color: #fff;
  font-size: 13px;
  line-height: 1.5em;
  .c_col{
    display: flex;
    margin-bottom: 6px;
    .c_lab{
      width: 100px;
    }
    .c_cnt{
      flex: 1;
    }
  }
}
.log_total{
  font-size: 14px;
  margin-top: 20px;
}
</style>
